<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<!-- 
  - Author(s): yangyong
  - Date: 2013-02-28 10:14:50
  - Description:
-->
<head>
<title>下级人员</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<%@include file="/coframe/tools/skins/common.jsp" %>
</head>
<body>
<div style="padding:5px 5px 0px 5px;">
	 <div class="nui-toolbar" style="border-bottom:0;">
        <table style="width:100%;">
            <tr>
	            <td style="width:100%;">
	                <a class="nui-button" iconCls="icon-reload" onclick="reloadAll" id="all_btn">同步当前显示的全部员工</a>
	            	<a class="nui-button" iconCls="icon-reload" onclick="reloadSel" id="sel_btn">同步本级机构选中的员工</a>
	            </td>
            </tr>
        </table>
    </div>
</div>
<div class="nui-fit" style="padding:0px 5px 5px 5px">
	<div id="datagrid1" class="nui-datagrid" style="width:100%;height:100%;" 
	url="org.gocom.components.coframe.org.synonyms.queryEmpUserForPortal.biz.ext" dataField="tree" idField="id" allowResize="true" sizeList="[10,20,50,100]" pageSize="10" multiSelect="true">
	    <div property="columns">
	        <div type="checkcolumn"></div>
	        <div field="empname" width="100" headerAlign="center" >人员姓名</div>    
	        <div field="empcode" width="100" headerAlign="center" >人员代码</div>    
	        <div field="gender" width="100" headerAlign="center" renderer="renderGender" >性别</div>    
	        <div field="empstatus" width="100" headerAlign="center" renderer="renderEmpStatus" >人员状态</div>    
	        <div field="userid" width="100" headerAlign="center" >用户登录名</div>    
	        <div field="status" width="100" headerAlign="center" renderer="renderStatus" >用户状态</div>    
	        <div field="sortno" width="100" headerAlign="center" >排序顺序</div>    
	    </div>
	</div>
</div>
 
<script type="text/javascript">
	nui.parse();
	
	(function(){
		if(window.parent.getCurrentNode){
			var node = window.parent.getCurrentNode();
			var parentNode = node;
			window['parentNode'] = parentNode;
		}
	})();
	//获得父节点
	var data = {parentNode:window.parentNode||{}};
	var grid = nui.get("datagrid1");
	grid.load({orgOrganization:data.parentNode});
	grid.sortBy("sortno", "asc");
	
	//同步全部
	function reloadAll(){
		var json = nui.encode({datas:grid.getData(),orgOrganization:data.parentNode});
		$.ajax({
    		url: "org.gocom.components.coframe.org.synonyms.addOrUpdateEmpUser.biz.ext",
    		type: 'POST',
    		data: json,
    		cache: false,
    		contentType:'text/json',
    		success: function (text) {
        		var returnJson = nui.decode(text);
				if(returnJson.resultStr == 'SUCCESS'){
					nui.alert("同步"+returnJson.index+"个员工信息","提示");
					//自动刷新
	                if(window.parent){
	               		window.parent.refreshCurrentNode();
					}
        		}
        		else{
        			nui.alert("同步失败","提示");
    			}
    		},
    		error: function () {
    		}
		});
	}

	//同步选择
	function reloadSel(){
		var rows = grid.getSelecteds();
		if(rows.length>0){
			var json = nui.encode({datas:rows,orgOrganization:data.parentNode});
			$.ajax({
	    		url: "org.gocom.components.coframe.org.synonyms.addOrUpdateEmpUser.biz.ext",
	    		type: 'POST',
	    		data: json,
	    		cache: false,
	    		contentType:'text/json',
	    		success: function (text) {
	        		var returnJson = nui.decode(text);
					if(returnJson.resultStr == 'SUCCESS'){
						nui.alert("同步"+returnJson.index+"个员工信息","提示");
						//自动刷新
		                if(window.parent){
		               		window.parent.refreshCurrentNode();
						}
	        		}
	        		else{
	        			nui.alert("同步失败","提示");
	    			}
	    		},
	    		error: function () {
	    		}
			});
		}else{
			nui.alert("请选择待同步的用户数据！","提示");
		}
	}	
	function renderGender(e){
		return nui.getDictText("COF_GENDER",e.row.gender);
	}
	
	function renderEmpStatus(e){
		return nui.getDictText("COF_EMPSTATUS",e.row.empstatus);
	}
	
	function renderStatus(e){
		 return nui.getDictText("COF_USERSTATUS",e.row.status);
	}
</script>

</body>
</html>